(function (Model) {
    /**
     * 客户类
     * @type type
     */
    var Custom = (function () {
        function Custom(c_name, c_addr, c_ctime, c_update, c_maturity) {
            this.name = c_name;
            this.addr = c_addr;
            this.persons = new Array();
            this.visits = new Array();
            this.deals = new Array();
            this.lastUpdate = c_update;
            this.createTime = c_ctime;
            this.maturity = c_maturity || 0;
        }

        Custom.TYPE_NONE = 0;           // 未分类（全部）
        Custom.TYPE_THISMONTH = 1;      // 本月
        Custom.TYPE_INTENTION = 2;      // 意向
        Custom.TYPE_DEAL = 3;           // 成交

        Custom.GROUP_TITLE = ["全部客户", "本月客户", "意向客户", "成交客户"];

        Custom.prototype.addPerson = function (p) {
            this.persons.push(p);
        };
        Custom.prototype.addVisit = function (v) {
            this.visits.push(v);
        };
        Custom.prototype.addDeal = function (d) {
            this.deals.push(d);
        };

        /**
         * 是否为本月客户
         * @returns {undefined}
         */
        Custom.prototype.isThisMonth = function () {
            return true;
        };
        /**
         * 是成交用户
         * @returns {undefined}
         */
        Custom.prototype.isDeal = function () {
            return this.deals && this.deals.length > 0;
        };
        /**
         * 是意向用户
         * @returns {undefined}
         */
        Custom.prototype.isIntention = function () {
            return false;
        };

        Custom.buildFromJson = function (data) {
            var custom = new Custom(data.name, data.addr, data.createTime, data.lastUpdate);
            var persons = data.persons;
            var visits = data.visits;
            var deals = data.deals;
            for (var i = 0; i < persons.length; i++) {
                custom.addPerson(Person.buildFromJson(persons[i]));
            }
            for (var i = 0; i < visits.length; i++) {
                custom.addVisit(Visits.buildFromJson(visits[i]));
            }
            for (var i = 0; i < deals.length; i++) {
                custom.addDeal(Deal.buildFromJson(deals[i]));
            }
            return custom;
        };
        return Custom;
    })();
    Model.Custom = Custom;
    /**
     * 联系人类
     * @type type
     */
    var Person = (function () {
        function Person(p_name, p_tel) {
            this.name = p_name;
            this.tel = p_tel;
        }

        Person.buildFromJson = function (data) {
            return new Person(data.name, data.tel);
        };
        return Person;
    })();
    Model.Person = Person;
    /**
     * 拜访记录类
     * @type type
     */
    var Visit = (function () {
        function Visit(v_pname, v_content, v_time, v_maturity) {
            this.person_name = v_pname;
            this.content = v_content;
            this.time = v_time;
            this.maturity = v_maturity;
        }

        Visit.buildFromJson = function (data) {
            return new Visit(data.person_name, data.content, data.time, data.maturity);
        };
        return Visit;
    })();
    Model.Visit = Visit;
    /**
     * 成交记录类
     * @type type
     */
    var Deal = (function () {
        function Deal(d_product, d_money, d_time) {
            this.product = d_product;
            this.money = d_money;
            this.time = d_time;
        }

        Deal.buildFromJson = function (data) {
            return new Deal(data.product, data.money, data.time);
        };
        return Deal;
    })();
    Model.Deal = Deal;
})(App.Model || (App.Model = {}));